package com.dinghui.salary.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.dinghui.salary.pojo.User;
import com.dinghui.salary.pojo.dto.MouthTypeDTO;
import com.dinghui.salary.pojo.dto.SalaryStructureDTO;
import com.dinghui.salary.pojo.dto.SearchMouthTypeDTO;
import com.dinghui.salary.service.MouthTypeService;
import com.dinghui.salary.utils.ApiResult;
import com.dinghui.salary.utils.LocalUser;
import com.dinghui.salary.utils.PagedGridResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * @author tanrentao
 * @date 2021-09-06
 * @desc 月工资类型
 */
@RestController
@RequestMapping("/mouthType")
@Api(value = "MouthTypeController", tags = "月工资类型")
public class MouthTypeController {

    @Reference(version = "2.0.0")
    MouthTypeService mouthTypeService;

    @ApiOperation("增加")
    @PostMapping("/create")
    public ApiResult create (@RequestBody MouthTypeDTO dto) {
        User user = LocalUser.getUser();
        mouthTypeService.create(dto, user);
        return ApiResult.success();
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public ApiResult update (@RequestBody MouthTypeDTO dto) {
        User user = LocalUser.getUser();
        return ApiResult.success(mouthTypeService.update(dto, user));
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    public ApiResult delete(@PathVariable String id) {
        return ApiResult.success(mouthTypeService.delete(id));
    }

    @ApiOperation("查询工资类型列表")
    @PostMapping("/findList")
    public ApiResult findList(@RequestBody SearchMouthTypeDTO dto) {
        PagedGridResult pagedGridResult = mouthTypeService.findList(dto);
        return ApiResult.success(pagedGridResult);
    }

    @ApiOperation("查询工资结构列表")
    @PostMapping("/getSalaryStructureList")
    public ApiResult getSalaryStructureList(@RequestBody SalaryStructureDTO dto) {
        PagedGridResult pagedGridResult = mouthTypeService.selectSalaryStructureList(dto);
        return ApiResult.success(pagedGridResult);
    }

    @ApiOperation("根据Id查询")
    @GetMapping("/findById/{id}")
    public ApiResult findById(@PathVariable String id) {
        return ApiResult.success(mouthTypeService.findById(id));
    }


    @ApiOperation("生成名单")
    @GetMapping("/generate/{id}")
    public ApiResult generate(@PathVariable String id) {
        User user = LocalUser.getUser();
        //mouthTypeService.generate(id, user);
        return ApiResult.success();
    }

}
